package com.hjwoo.app.ui;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.ScrollView;

public class ObservableScrollView extends ScrollView
{

    private boolean mDisableEdgeEffects = true;
    private OnScrollChangedListener mOnScrollChangedListener;

    public ObservableScrollView(Context context)
    {
        super(context);
    }

    public ObservableScrollView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public ObservableScrollView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onScrollChanged(int x, int y, int oldx, int oldy)
    {
        super.onScrollChanged(x, y, oldx, oldy);
        if (mOnScrollChangedListener != null)
        {
            mOnScrollChangedListener.onScrollChanged(this, x, y, oldx, oldy);
        }
    }

    public void setOnScrollChangedListener(OnScrollChangedListener listener)
    {
        mOnScrollChangedListener = listener;
    }

    @Override
    protected float getTopFadingEdgeStrength()
    {
        if (mDisableEdgeEffects && Build.VERSION.SDK_INT < 11)
        {
            return 0.0f;
        }
        return super.getTopFadingEdgeStrength();
    }

    @Override
    protected float getBottomFadingEdgeStrength()
    {

        if (mDisableEdgeEffects && Build.VERSION.SDK_INT < 11)
        {
            return 0.0f;
        }
        return super.getBottomFadingEdgeStrength();
    }

    public interface OnScrollChangedListener
    {
        void onScrollChanged(ScrollView scrollview, int X, int y, int oldx, int oldy);
    }
}
